/**
 * Created by Mars on 2016/12/13.
 * Updated by Tsuna Cheung on 2016-12-15
 * Updated by qiangqiang on 2016-12-21
 * Updated by Tsuna Cheung on 2016-12-22
 */
import React, {Component} from 'react';
import{
    StyleSheet,
    Navigator,
    View,
    Text,
    ScrollView,
    BackAndroid,
    Platform
} from 'react-native';

import Starrating from 'react-native-star-rating';
import Header from '../component/Header';

export default class AnnualEvaluation extends Component {
    constructor(props) {
        super(props);
        this.state = {
            starCount: 3.5
        };
    }

    onStarRatingPress(rating) {
        this.setState({
            starCount: rating
        });
    }

    _backtoMeTab = () => {
        const {navigator} = this.props;
        if (navigator) {
            navigator.pop();
        }
    };

    componentWillMount() {
        if (Platform.OS === 'android') {
            BackAndroid.addEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    componentWillUnmount() {
        if (Platform.OS === 'android') {
            BackAndroid.removeEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    /* Android返回键执行的操作 被之前BackAndoid组件调用*/
    onBackAndroid = () => {
        const {navigator} = this.props;
        const routers = navigator.getCurrentRoutes();
        if (routers.length > 1) {
            navigator.pop();
            return true;
        }
        return false;
    };

    render() {
        return (
            <View style={styles.container}>
                <Header name="年度评价"
                        function={this._backtoMeTab}/>

                <View style={styles.body}>
                    <View style={styles.above}>
                        <Text style={styles.above_text}>
                            总分
                        </Text>

                        <View style={styles.body_star}>
                            <Starrating
                                disabled={false}
                                starSize={25}
                                maxStars={5}
                                starColor={"#EEB422"}
                                rating={this.state.starCount}
                                selectedStar={(rating) => this.onStarRatingPress(rating)}
                            />
                        </View>
                    </View>

                    <View style={styles.below}>
                        <ScrollView style={{flex: 1}}>
                            <View style={styles.below_view}>

                                <Text style={styles.below_text_year}>
                                    2017年
                                </Text>



                                <Text style={styles.below_text_info}>
                                    年度自我评价：还算满意
                                </Text>

                                <Text style={styles.below_text_info}>
                                    上级评价：总体来说不错，还需要继续努力。
                                </Text>
                            </View>

                            <View style={styles.below_view}>
                                <Text style={styles.below_text_year}>
                                    2016年
                                </Text>


                                <Text style={styles.below_text_info}>
                                    年度自我评价：还算满意
                                </Text>

                                <Text style={styles.below_text_info}>
                                    上级评价：总体来说不错，还需要继续努力。
                                </Text>
                            </View>

                            <View style={styles.below_view}>
                                <Text style={styles.below_text_year}>
                                    2015年
                                </Text>

                                <Text style={styles.below_text_info}>
                                    年度自我评价：还算满意
                                </Text>

                                <Text style={styles.below_text_info}>
                                    上级评价：总体来说不错，还需要继续努力。
                                </Text>
                            </View>
                        </ScrollView>
                    </View>
                </View>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1
    },
    body: {
        flex: 10
    },
    above: {
        flexDirection: "row",
        flex: 1,
        alignItems: "center",
        borderBottomWidth: 1,
        borderColor: "#CACACA"
    },
    above_text: {
        fontSize: 25,
        marginLeft: 30,
    },
    below: {
        flex: 9
    },
    below_view: {
        justifyContent: "center",
        borderBottomWidth: 1,
        borderColor: "#CACACA",
        flex: 1
    },
    below_text_year: {
        fontSize: 25,
        marginLeft: 30,
        marginTop: 10
    },
    below_text_info: {
        fontSize: 12,
        marginBottom: 15,
        marginLeft: 30
    },
    body_star: {
        marginLeft: 5,
        marginTop: -5
    },
});